<template>
	<view class="container">
		<view class="v-tdyj-container">
			<view class="v-tdyj-item" v-for="(item, index) in datas.TDYJs">
				<view class="v-item-header">
					{{ formatDay(item.StatisticDay) }}
				</view>
				<view class="v-item-member" v-for="(mItem, index) in item.Members">
					<view class="v-item-group">
						<view class="v-item-left">{{ mItem.UserInfo.NickName }}</view>
					</view>
					<view class="v-item-group">
						<view class="v-item-left">成本：{{ mItem.LJZC_CB_JR }}</view>
						<view class="v-item-right">上架费：{{ mItem.LJZC_SHF }}</view>
					</view>
					<view class="v-item-group">
						<view class="v-item-left">支出：{{ mItem.LJZC_JR }}</view>
						<view class="v-item-right">收入：{{ mItem.LJSY_JR }}</view>
					</view>
				</view>
				<view class="v-item-summary">
					<view class="v-item-group">
						<view class="v-item-left">累计支出：{{ item.LJZCSummary }}</view>
						<view class="v-item-right">累计收益：{{ item.LJSYSummary }}</view>
					</view>
				</view>
			</view>
		</view>
		<uni-popup ref="message" type="message" class="pop-msg">
			<uni-popup-message :type="msgType" :message="messageText" :duration="duration"></uni-popup-message>
		</uni-popup>
		<!-- 提示窗示例 -->
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog type="warn" cancelText="关闭" confirmText="确定" title="提醒" :content="dialogMsg" @confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import {
		dateUtils,
		authTokenUtil,
		validLoginToken
	} from "../../common/util.js"
export default {
	data() {
		return {
			messageText: '',
			msgType: 'success',
			duration: 2000,

			datas: {
				TDYJs: [
					// {
					// 	StatisticDay: '2024-04-10',
					// 	LJZC: 2356.56,
					// 	LJSY: 5689.89,
					// 	Members: [
					// 		{
					// 			NickName: '哈哈1',
					// 			CB: 5623.23,
					// 			SJF: 78.23,
					// 			ZC: 789.56,
					// 			SY: 897.23
					// 		},
					// 		{
					// 			NickName: '哈哈2',
					// 			CB: 5623.23,
					// 			SJF: 78.23,
					// 			ZC: 789.56,
					// 			SY: 897.23
					// 		}
					// 	]
					// }
				]
			}
		};
	},
	methods: {
		formatDay: function (time) {
			// 创建一个新的Date对象
			const today = new Date(time);

			// 使用getDay()方法获取星期几的数字表示
			const dayIndex = today.getDay();

			// 创建一个数组，包含星期几的名称
			const daysOfWeek = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];

			// 根据dayIndex从数组中获取对应的星期名称
			const dayName = daysOfWeek[dayIndex];

			return `${time.toString().substring(0,10)} ${dayName}`;
		},
		loadInfo: function () {
			let _this = this;

			//正式代码
			var authToken = authTokenUtil();
			var queryData = {
				UserId: _this.datas.UserId
			};
			uni.request({
				url: _this.sysInfo.BasePath + 'Sys/GetTeamStatisticDetailInfo',
				method: 'POST',
				data: queryData,
				header: {
					'content-type': 'application/json',
					Authorization: `${authToken}`
				},
				success: (res) => {
					if (res && res.data && res.data.Succeeded === true) {
						console.log(res);
						_this.datas.TDYJs = res.data.Data;
					} else {
						_this.sysUtils.tip({
							sender: _this,

							title: '加载团队业绩明细信息失败！',
							icon: 'error'
						});
					}
				},
				fail: () => {
					_this.sysUtils.tip({
						sender: _this,
						title: '加载团队业绩明细信息失败！',
						icon: 'error'
					});
				},
				complete: () => {}
			});
		},
		init: function () {
			let _this = this;
			console.log('init');
			_this.loadInfo();
		}
	},
	onShow() {
		let _this = this;
		// _this.init();
	},
	onLoad(options) {
		let _this = this;
		_this.datas.UserId = options.UserId;

		_this.init();
		// options 包含了查询参数
		console.log(_this.datas.UserId);
	},
	created() {
		let _this = this;
		validLoginToken(null, () => {
			uni.reLaunch({
				url: "/pages/account/login"
			})
		})
	}
};
</script>

<style>
.container {
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
	align-items: stretch;
	/* background-color: #f0f0f0; */
	height: 100%;
}
.v-tdyj-container {
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
	align-items: stretch;
	padding: 20rpx;
	box-sizing: border-box;
}
.v-tdyj-item {
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
	align-items: stretch;
	background-color: #fff;
	border-radius: 20rpx;
	margin-bottom: 20rpx;
	
	box-shadow: 0rpx 5rpx 10rpx #999;
}
.v-item-header {
	display: flex;
	flex-direction: row;
	justify-content: flex-start;
	align-items: center;
	background-color: #c93a00ff;
	color: #fff;
	font-size: 26rpx;
	font-weight: bold;
	padding: 20rpx;
	border-radius: 20rpx 20rpx 0 0;
}
.v-item-member {
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
	align-items: stretch;
	margin: 20rpx 20rpx 0rpx 20rpx;
	border-bottom: solid 1px #f0f0f0;
	padding-bottom: 10rpx;
}
.v-item-group {
	display: flex;
	flex-direction: row;
	justify-content: flex-start;
	align-items: stretch;
	font-size: 26rpx;
	color: #333;
	height: 50rpx;
}
.v-item-left {
	display: flex;
	flex-direction: row;
	justify-content: flex-start;
	align-items: stretch;
	flex: 1;
}
.v-item-right {
	display: flex;
	flex-direction: row;
	justify-content: flex-start;
	align-items: stretch;
	flex: 1;
}
.v-item-summary {
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
	align-items: stretch;
	margin: 10rpx;
	font-weight: bold;
}
</style>
